package com.yc.mvplib;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import com.yc.mvplib.Retrofit.HttpConfig;
import com.yc.mvplib.manager.GlideManager;
import com.yc.mvplib.manager.LoggerManager;


/**
 * Function: 全局参数配置--可在Application处设置Library全局属性
 * Description:
 */
public class FastConfig {
    private static volatile FastConfig sInstance;
    private static Context mContext;
    public static final int REQUEST_CODE_SETTING=110;

    /**
     * Activity或Fragment根布局背景
     */
    @DrawableRes
    private int mContentViewBackgroundResource = -1;
    private int mRequestedOrientation;
    public static FastConfig getInstance(@Nullable Context context) {
        if (sInstance == null) {
            synchronized (FastConfig.class) {
                if (sInstance == null) {
                    sInstance = new FastConfig(context);
                }
            }
        }
        return sInstance;
    }
    public static FastConfig  getInstance(){
        return sInstance;
    }
    private FastConfig(@Nullable Context context) {
        this.mContext = context.getApplicationContext();
        init();
    }
    public void init(){
    if (mContext != null) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        setContentViewBackgroundResource(-1);
        setPlaceholderColor(getColor(R.color.colorPlaceholder));
        setPlaceholderRoundRadius(mContext.getResources().getDimension(R.dimen.dp_placeholder_radius));
        LoggerManager.init("Tag",BuildConfig.DEBUG);
    }
}


    public int getContentViewBackgroundResource() {
        return mContentViewBackgroundResource;
    }

    /**
     * 设置 Activity或Fragment根布局背景资源
     * 最终调用{@link: BasisActivity#beforeInitView()} {@link: BasisFragment#beforeInitView()}
     *
     * @param contentViewBackgroundResource
     * @return
     */
    public void setContentViewBackgroundResource(@DrawableRes int contentViewBackgroundResource) {
        mContentViewBackgroundResource = contentViewBackgroundResource;
    }
    public void setHttpBaseUrl(String url){
        HttpConfig.BASE_URL=url;
    }
    public int getRequestedOrientation() {
        return mRequestedOrientation;
    }

    /**
     * 设置Activity屏幕方向
     * 最终调用{@link: BasisActivity#onCreate(Bundle)}
     *
     * @param mRequestedOrientation 默认自动 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
     *                              竖屏 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
     *                              横屏 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
     *                              {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}}
     * @return
     */
    public void setRequestedOrientation(int mRequestedOrientation) {
        this.mRequestedOrientation = mRequestedOrientation;
    }


    /**
     * 设置加载图片占位图颜色
     *
     * @param mPlaceholderColor
     * @return
     */
    public void setPlaceholderColor(@ColorInt int mPlaceholderColor) {
        GlideManager.setPlaceholderColor(mPlaceholderColor);
    }

    /**
     * 设置加载图片占位图圆角弧度
     *
     * @param mPlaceholderRoundRadius
     * @return
     */
    public void setPlaceholderRoundRadius(float mPlaceholderRoundRadius) {
        GlideManager.setPlaceholderRoundRadius(mPlaceholderRoundRadius);
    }



    public int getColor(@ColorRes int color) {
        if (mContext==null){
            return 0;
        }
        return mContext.getResources().getColor(color);
    }

    public String getString(@ColorRes int id) {
        if (mContext==null){
            return "";
        }
        return mContext.getResources().getString(id);
    }
}
